package MobileApplicationDeveloper.diagram.navigator;

import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ITreePathLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.ViewerLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;

/**
 * @generated
 */
public class MobileApplicationDeveloperNavigatorLabelProvider extends
		LabelProvider implements ICommonLabelProvider, ITreePathLabelProvider {

	/**
	 * @generated
	 */
	static {
		MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put("Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
		MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
		Object element = elementPath.getLastSegment();
		if (element instanceof MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem
				&& !isOwnView(((MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem) element)
						.getView())) {
			return;
		}
		label.setText(getText(element));
		label.setImage(getImage(element));
	}

	/**
	 * @generated
	 */
	public Image getImage(Object element) {
		if (element instanceof MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup) {
			MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup group = (MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup) element;
			return MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().getBundledImage(group.getIcon());
		}

		if (element instanceof MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem) {
			MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem navigatorItem = (MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return super.getImage(element);
			}
			return getImage(navigatorItem.getView());
		}

		return super.getImage(element);
	}

	/**
	 * @generated
	 */
	public Image getImage(View view) {
		switch (MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
				.getVisualID(view)) {
		case MobileApplicationDeveloper.diagram.edit.parts.ContainerEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Diagram?ar.edu.unlp?Container", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Container_1000); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.LabelEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?Label", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Label_2001); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ViewEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?View", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.View_2002); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?AppMobile", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.AppMobile_2003); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.InputEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?Input", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Input_2004); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ListEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?List", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.List_2005); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.SettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?Setting", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Setting_2006); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ImageEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?ar.edu.unlp?Image", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Image_2007); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewEventsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?View?viewEvents", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.ViewViewEvents_4001); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileMainViewEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?AppMobile?mainView", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.AppMobileMainView_4002); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ComponentComponentEventsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?Component?componentEvents", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.ComponentComponentEvents_4003); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewSettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?View?viewSetting", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.ViewViewSetting_4004); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileAppSettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?AppMobile?appSetting", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.AppMobileAppSetting_4005); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewComponentsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?View?viewComponents", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.ViewViewComponents_4006); //$NON-NLS-1$
		case MobileApplicationDeveloper.diagram.edit.parts.ViewNextViewsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?ar.edu.unlp?View?nextViews", MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.ViewNextViews_4007); //$NON-NLS-1$
		}
		return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private Image getImage(String key, IElementType elementType) {
		ImageRegistry imageRegistry = MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
				.getInstance().getImageRegistry();
		Image image = imageRegistry.get(key);
		if (image == null
				&& elementType != null
				&& MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes
						.isKnownElementType(elementType)) {
			image = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes
					.getImage(elementType);
			imageRegistry.put(key, image);
		}

		if (image == null) {
			image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
			imageRegistry.put(key, image);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public String getText(Object element) {
		if (element instanceof MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup) {
			MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup group = (MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorGroup) element;
			return group.getGroupName();
		}

		if (element instanceof MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem) {
			MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem navigatorItem = (MobileApplicationDeveloper.diagram.navigator.MobileApplicationDeveloperNavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return null;
			}
			return getText(navigatorItem.getView());
		}

		return super.getText(element);
	}

	/**
	 * @generated
	 */
	public String getText(View view) {
		if (view.getElement() != null && view.getElement().eIsProxy()) {
			return getUnresolvedDomainElementProxyText(view);
		}
		switch (MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
				.getVisualID(view)) {
		case MobileApplicationDeveloper.diagram.edit.parts.ContainerEditPart.VISUAL_ID:
			return getContainer_1000Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.LabelEditPart.VISUAL_ID:
			return getLabel_2001Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ViewEditPart.VISUAL_ID:
			return getView_2002Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileEditPart.VISUAL_ID:
			return getAppMobile_2003Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.InputEditPart.VISUAL_ID:
			return getInput_2004Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ListEditPart.VISUAL_ID:
			return getList_2005Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.SettingEditPart.VISUAL_ID:
			return getSetting_2006Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ImageEditPart.VISUAL_ID:
			return getImage_2007Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewEventsEditPart.VISUAL_ID:
			return getViewViewEvents_4001Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileMainViewEditPart.VISUAL_ID:
			return getAppMobileMainView_4002Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ComponentComponentEventsEditPart.VISUAL_ID:
			return getComponentComponentEvents_4003Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewSettingEditPart.VISUAL_ID:
			return getViewViewSetting_4004Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.AppMobileAppSettingEditPart.VISUAL_ID:
			return getAppMobileAppSetting_4005Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ViewViewComponentsEditPart.VISUAL_ID:
			return getViewViewComponents_4006Text(view);
		case MobileApplicationDeveloper.diagram.edit.parts.ViewNextViewsEditPart.VISUAL_ID:
			return getViewNextViews_4007Text(view);
		}
		return getUnknownElementText(view);
	}

	/**
	 * @generated
	 */
	private String getContainer_1000Text(View view) {
		MobileApplicationDeveloper.model.Container domainModelElement = (MobileApplicationDeveloper.model.Container) view
				.getElement();
		if (domainModelElement != null) {
			return domainModelElement.getAppName();
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance()
					.logError(
							"No domain element for view with visualID = " + 1000); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getLabel_2001Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Label_2001,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.LabelNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5001); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getView_2002Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.View_2002,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.ViewViewNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5002); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getAppMobile_2003Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.AppMobile_2003,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.AppMobileAppNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5003); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getInput_2004Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Input_2004,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.InputNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5004); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getList_2005Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.List_2005,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.ListNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5005); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getSetting_2006Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Setting_2006,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.SettingSettingNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5006); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getImage_2007Text(View view) {
		IParser parser = MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperParserProvider
				.getParser(
						MobileApplicationDeveloper.diagram.providers.MobileApplicationDeveloperElementTypes.Image_2007,
						view.getElement() != null ? view.getElement() : view,
						MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
								.getType(MobileApplicationDeveloper.diagram.edit.parts.ImageNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperDiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5007); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getViewViewEvents_4001Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getAppMobileMainView_4002Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getComponentComponentEvents_4003Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewViewSetting_4004Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getAppMobileAppSetting_4005Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewViewComponents_4006Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewNextViews_4007Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getUnknownElementText(View view) {
		return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	private String getUnresolvedDomainElementProxyText(View view) {
		return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	public void init(ICommonContentExtensionSite aConfig) {
	}

	/**
	 * @generated
	 */
	public void restoreState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public void saveState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public String getDescription(Object anElement) {
		return null;
	}

	/**
	 * @generated
	 */
	private boolean isOwnView(View view) {
		return MobileApplicationDeveloper.diagram.edit.parts.ContainerEditPart.MODEL_ID
				.equals(MobileApplicationDeveloper.diagram.part.MobileApplicationDeveloperVisualIDRegistry
						.getModelID(view));
	}

}
